<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    
    <link rel="stylesheet" href="__HOME__/css/weui.css">
    <link rel="stylesheet" href="__HOME__/css/jquery-weui.css">
    <link rel="stylesheet" href="__HOME__/css/style.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_729135_t2loq20h12.css">

    <script src="__HOME__/js/jquery.min.js"></script>
    <script src="__HOME__/js/jquery-weui.min.js"></script>
   
    <style>
    
    </style>
</head>
<body class="back1">    
    <div class="index-top-fix">
        <a href="{:url('store/teacher.article/list_article')}" class="iconfont icon-left- left"></a>
        <p class="title">发布文章</p>
    </div>
    <div class="mt50"></div>
    <div class="weui-cells weui-cells_form"style="width: 95%;margin: 0 auto;">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">标题</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" placeholder="请输入标题" value="{$article.title}" id="title" name="title">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">作者</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" value="{$article.author}" placeholder="请输入作者名称" id="author" name="author">
            </div>
        </div>
        <div class="weui-cell weui-cell_select" style="background-color: #fff">
            <span style="margin-left: 15px">分类：</span>
            <div class="weui-cell__bd" style="margin-left: 38px">

                <select class="weui-select" name="sort" id="sort" value="" style="">
                    <option value="" style="">请选择文章类别</option>
                    {foreach $sort as $data}
                    <option value="{$data.sort}" style="">{$data.sort}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="weui-cell">
        <div class="weui-cell__bd">
        <textarea class="weui-textarea" id="content"  placeholder="请输入文章内容" rows="15">{$article.content}</textarea>
        </div>
        </div>
    </div> 
    <div style="width: 95%;margin: 15px auto">
        <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="refer(this)">提交</a>
    </div>
</body>
<script>


    //文章分类
    function setSelect(ele, val) {

        $('#' + ele + ' option').each(function (index, ele) {
            var el = $(ele);
            if (el.attr('value') == val) {
                el.attr('selected', 'selected')
            } else {
                el.removeAttr('selected');
            }
        })

    }

    $(function () {
        setSelect('sort', "{$article.sort}")
    });
 function refer(that){
     var title 		= $("#title").val();
     var sort 		= $("#sort").val();
     var content = $("#content").val();
     var author = $("#author").val();
     var id="{$article.id}";
     // 标题不可为空
     if(title === '' || title === "undefined"){
         $.alert('请填写标题');
         $("#title").focus();
         return;
     }

     // 作者不可为空
     if(author === '' || author === "undefined"){
         $.alert('请填写作者');
         $("#author").focus();
         return;
     }
     // 文章内容不可为空
     if(content === '' || content === "undefined"){
         $.alert('请填写文章内容');
         $("#content").focus();
         return;
     }
     // 分类不可为空
     if(sort === '' || sort === "undefined"){
         $.alert('请选择文章分类');
         $("#sort").focus();
         return;
     }
     $.confirm("每篇文章只可编辑一次，确认提交?","确认提交?",function () {
         $.post('{:url("edit_article")}',{title:title,sort:sort,content:content,author:author,id:id},function(res){
             if(res.code==1){

                 $.toast(res.msg);
                 // 定时跳转
                 setTimeout(function(){
                     location.href="{:url('store/teacher.index/list_article')}";
                     console.log("success");
                 },1500);
             }else{
                 $.alert(res.msg,function () {
                     return false;
                 });
             }
         })
     },function () {
         //取消操作
     })

 }
</script>
</html>

